package com.wjl.tableanalyzier.strategy;

import java.util.regex.Pattern;

public abstract class ColumnStrategy {

    private static final Pattern pattern = Pattern.compile("^\\w+(\\(\\d+\\)){1}$");

    public ColumnStrategy() {
        ColumnStrategyRegistry.register(this);
    }

    public abstract boolean match(String type);

    public abstract int getSize(String type);

    protected Pair<String, Integer> split(String type) {
        if (pattern.matcher(type).find()) {
            return Pair.of(type.substring(0, type.indexOf(')')),
                    Integer.parseInt(type.substring(type.indexOf('(') + 1, type.length() - 1)));
        }
        return Pair.of(type, 0);
    }
}
